﻿using Architecture.CrossCutting.Web.Tracing.Model;
using Microsoft.Diagnostics.Tracing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.CrossCutting.Web.Tracing.ETW
{
    public class ETWWebApiLogParser
    {
        public static ETWWebApiLogParser Current = new ETWWebApiLogParser();

        public WebApiLog_bck CreateFromEventWebApi(TraceEvent data)
        {
            return new WebApiLog_bck()
            {
                LogId = Guid.NewGuid(),
                CorrelationId = data.ActivityID,
                EventIndex = (int)data.EventIndex,
                EventName = data.EventName,
                Level = data.Level.ToString(),
                Operation = data.OpcodeName,
                TaskName = data.TaskName,
                ThreadId = data.ThreadID,
                ProcessId = data.ProcessID,
                CreationTime = data.TimeStamp,
                Uri = (String)data.PayloadByName("Uri"),
                Method = (String)data.PayloadByName("Method"),
                statusCode = data.PayloadByName("statusCode") == null ? null : data.PayloadByName("statusCode").ToString()
            };
        }
    }
}
